'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 副本记录
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var mongoConnector = require('../libs/mongodb/mongoConnector');
/* jshint unused:false */
var bossRecordSchema = require('../schemas/bossRecordSchema');
var BossRecord = mongoConnector().model('BossRecord');
var dataApi = require('../libs/dataApi');

var bossRecordModel = module.exports;

/**
 * 添加一个战斗记录
 */
bossRecordModel.addRecord = function (atk_role_id, atk, def, cb) {
    // 创建成功后
    function afterCreate(err, model) {
        if (!!err) {
            console.error(err);
            return cb(err);
        }
        cb(err, model);
    }

    BossRecord.create({
        atk_role_id: atk_role_id,
        atk: atk,
        def: def,
    }, afterCreate);
};

/**
 * 获取一个战斗记录
 */
bossRecordModel.getRecordByAtkRoleId = function (atk_role_id, record_id, cb) {
    BossRecord.findById(record_id, function (err, boss_record_model) {
        if (!!boss_record_model && boss_record_model.getAtkRoleId() != atk_role_id) {
            cb(new Error('boss record not found'));
        } else {
            cb(null, boss_record_model);
        }
    });
};
